home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / demo / medit.zip / DOCVIEW.CPP < prev    next >
C/C++ Source or Header  |  1994-08-29  |  3KB  |  118 lines

  1. #include "stdafx.h"
  2. #include "magmaed.hpp"
  3. #include "multipad.h"
  4. #include "mainfrm.h"
  5.  
  6. #define USE_MAGMA
  7.  
  8. IMPLEMENT_DYNCREATE(CPadDoc, CDocument)
  9. BEGIN_MESSAGE_MAP(CPadDoc, CDocument)
  10.     //{{AFX_MSG_MAP(CPadDoc)
  11.     ON_UPDATE_COMMAND_UI(ID_INDICATOR_OVR, OnUpdateIndicatorOvr)
  12.     ON_UPDATE_COMMAND_UI(ID_INDICATOR_COL, OnUpdateIndicatorCol)
  13.     ON_UPDATE_COMMAND_UI(ID_INDICATOR_CURRLINE, OnUpdateIndicatorCurrLine)
  14.     ON_UPDATE_COMMAND_UI(ID_INDICATOR_NUMLINES, OnUpdateIndicatorNumLines)
  15.         ON_COMMAND(ID_OPT_FONT, OnChooseFont)
  16.     //}}AFX_MSG_MAP
  17. END_MESSAGE_MAP()
  18.  
  19. void CPadDoc::Serialize(CArchive& ar)
  20. {
  21. #ifdef USE_MAGMA
  22.   ((CMagmaEditView*)m_viewList.GetHead())->SerializeRaw(ar);
  23. #else
  24.   ((CEditView*)m_viewList.GetHead())->SerializeRaw(ar);
  25. #endif
  26. }
  27.  
  28.  
  29. MAGMAED_STATUS &CPadDoc::GetStatus()
  30. {
  31.   POSITION pos = GetFirstViewPosition();
  32.   MAGMAED_STATUS &meStatus =
  33.                  ((CMagmaEditView *) GetNextView(pos))->GetStatus();
  34.   return meStatus;
  35. }
  36.  
  37. void CPadDoc::OnUpdateIndicatorOvr(CCmdUI* pCmdUI)
  38. {
  39.   // TODO: Add your command update UI handler code here
  40.   pCmdUI->Enable();
  41.  
  42.   MAGMAED_STATUS &meStatus = GetStatus();
  43.   if (meStatus.bInsert);
  44.     pCmdUI->SetText(meStatus.bInsert ? "INS" : "OVR");
  45. }
  46.  
  47.  
  48. void CPadDoc::OnUpdateIndicatorCol(CCmdUI* pCmdUI)
  49. {
  50.   // TODO: Add your command update UI handler code here
  51.   pCmdUI->Enable();
  52.   if (!(GetKeyState(VK_LBUTTON) & 0x8000))
  53.   {
  54.     MAGMAED_STATUS &meStatus = GetStatus();
  55.     char szBuf[32];
  56.     wsprintf(szBuf, "%3d", meStatus.column+1);
  57.     pCmdUI->SetText(szBuf);
  58.   }
  59. }
  60.  
  61. void CPadDoc::OnUpdateIndicatorCurrLine(CCmdUI* pCmdUI)
  62. {
  63.   // TODO: Add your command update UI handler code here
  64.   pCmdUI->Enable();
  65.   if (!(GetKeyState(VK_LBUTTON) & 0x8000))
  66.   {
  67.     MAGMAED_STATUS &meStatus = GetStatus();
  68.     char szBuf[32];
  69.     wsprintf(szBuf, "%5d", meStatus.currLineNum);
  70.     pCmdUI->SetText(szBuf);
  71.   }
  72. }
  73.  
  74. void CPadDoc::OnUpdateIndicatorNumLines(CCmdUI* pCmdUI)
  75. {
  76.   // TODO: Add your command update UI handler code here
  77.   pCmdUI->Enable();
  78.   if (!(GetKeyState(VK_LBUTTON) & 0x8000))
  79.   {
  80.     MAGMAED_STATUS &meStatus = GetStatus();
  81.     char szBuf[32];
  82.     wsprintf(szBuf, "%5d", meStatus.nTotalLines);
  83.     pCmdUI->SetText(szBuf);
  84.   }
  85. }
  86.  
  87. void CPadDoc::OnChooseFont()    // placed in CPadDoc only for quick testing,
  88.                                 // to avoid creating a new view class
  89. {
  90. #ifdef USE_MAGMA
  91.   CMagmaEditView* pView = (CMagmaEditView*)m_viewList.GetHead();
  92. #else
  93.   CEditView* pView = (CEditView*)m_viewList.GetHead();
  94. #endif
  95.  
  96.   // get current font description
  97.   CFont* pFont = pView->GetFont();
  98.   LOGFONT lf;
  99.   if (pFont != NULL)
  100.     pFont->GetObject(sizeof(LOGFONT), &lf);
  101.   else
  102.     ::GetObject(GetStockObject(SYSTEM_FONT), sizeof(LOGFONT), &lf);
  103.  
  104.   CFontDialog dlg(&lf, CF_SCREENFONTS|CF_INITTOLOGFONTSTRUCT);
  105.   if (dlg.DoModal() == IDOK)
  106.   {
  107.     // switch to new font.
  108.     pFont->DeleteObject();
  109.     if (pFont->CreateFontIndirect(&lf))
  110.     {
  111.       pView->SetFont(pFont);
  112.     }
  113.   }
  114. }
  115.  
  116. /////////////////////////////////////////////////////////////////////////////
  117.  
  118.